package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileTransfer;
import com.spvs.system.service.IFileTransferService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 文件传输Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/transfer")
public class FileTransferController extends BaseController
{
    @Autowired
    private IFileTransferService fileTransferService;

    /**
     * 查询文件传输列表
     */
    @RequiresPermissions("system:transfer:list")
    @GetMapping("/list")
    public TableDataInfo list(FileTransfer fileTransfer)
    {
        startPage();
        List<FileTransfer> list = fileTransferService.selectFileTransferList(fileTransfer);
        return getDataTable(list);
    }

    /**
     * 导出文件传输列表
     */
    @RequiresPermissions("system:transfer:export")
    @Log(title = "文件传输", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileTransfer fileTransfer)
    {
        List<FileTransfer> list = fileTransferService.selectFileTransferList(fileTransfer);
        ExcelUtil<FileTransfer> util = new ExcelUtil<FileTransfer>(FileTransfer.class);
        util.exportExcel(response, list, "文件传输数据");
    }

    /**
     * 获取文件传输详细信息
     */
    @RequiresPermissions("system:transfer:query")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(fileTransferService.selectFileTransferByFileId(fileId));
    }

    /**
     * 新增文件传输
     */
    @RequiresPermissions("system:transfer:add")
    @Log(title = "文件传输", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileTransfer fileTransfer)
    {
        return toAjax(fileTransferService.insertFileTransfer(fileTransfer));
    }

    /**
     * 修改文件传输
     */
    @RequiresPermissions("system:transfer:edit")
    @Log(title = "文件传输", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileTransfer fileTransfer)
    {
        return toAjax(fileTransferService.updateFileTransfer(fileTransfer));
    }

    /**
     * 删除文件传输
     */
    @RequiresPermissions("system:transfer:remove")
    @Log(title = "文件传输", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(fileTransferService.deleteFileTransferByFileIds(fileIds));
    }
}
